﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lilium.Control
{
    [Obsolete("Not control structure")]
    public static class Maybe
    {
        public static Maybe<TValue> Create<TValue>(TValue value)
        {
            return new Maybe<TValue>(true, value);
        }

        public static Maybe<TValue> Create<TValue>(bool hasValue, Func<TValue> valueProvider)
        {
            if (hasValue)
                return new Maybe<TValue>(true, valueProvider());
            else
                return new Maybe<TValue>(false, default(TValue));
        }
    }

    [Obsolete("Not control structure")]
    public struct Maybe<TValue>
    {
        public Maybe(bool hasValue, TValue value)
        {
            m_Value = value;
            m_HasValue = hasValue;
        }

        #region public bool HasValue

        private bool m_HasValue;

        public bool HasValue
        {
            get { return m_HasValue; }
            set { m_HasValue = value; }
        }

        #endregion

        #region public TValue Value

        private readonly TValue m_Value;

        public TValue Value
        {
            get
            {
                return m_Value;
            }
        }

        #endregion
    }
}